<?php include("includes/session.php"); ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo $lang['PAGE_TITLE_EDIT_PROJECT_NEWS']; ?></title>
<?php include("header.php"); ?>
	<br />
	<center>
	<table width="97%">
	<tr>
		<td valign="top" width="14%">
			<table cellpadding="0" cellspacing="0">
			<tr>
				<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
			</tr>
			<tr bgcolor="#dadada">
				<td></td><td>
				<center><a href="viewProject.php?id=<?php echo htmlspecialchars($_GET['id']); ?>"><?php echo $lang['EDIT_PROJECT_BACKTOPROJECT']; ?></a></center>
				</td><td></td>
			</tr>
			<tr>
				<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
			</tr>
			</table>
		</td>
		<td valign="top">
			<?php 
			$project = $database->getProject($_GET['id']);
			if($project=="")
			{
				echo "<br /><center>No Project Found</center>";
			}
			else
			{
				$resul = $database->query("SELECT * FROM ".TBL_PROJECT_MEMBERS." WHERE projectID='".$project['id']."' AND username='".$session->username."'");
				$projectMember = mysql_fetch_array($resul);
					
				if(!$session->logged_in)
				{
					echo "<center><h2>Restricted Area</h2></center>";
					echo "<center>Please <a href=\"index.php\">Log In</a>.</center>";
				}
				else if($project['creator']==$session->username || $session->userlevel>=MANAGER_LEVEL || $projectMember['userlevel']>=PROJECT_MANAGER)
				{
			?>
			<center>
			<table cellpadding="0" cellspacing="0">
			<tr>
				<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
			</tr>
			<tr bgcolor="#dadada">
				<td></td><td>
				<center><font size="+1"><b><?php if(isset($_GET['edit'])){ echo "Edit Project News"; }else{ echo "Post Project News"; } ?></b></font></center>
				<center>
				<?php
					if($_SESSION['projectnewssuccess'])
					{
						echo "<br /><center>News Posted!";
						echo "<br /><a href=\"viewProject.php?id=".$_GET['id']."\">View Project</a></center>";
						unset($_SESSION['projectnewssuccess']);
					}
					else if($_SESSION['editprojectnewssuccess'])
					{
						echo "<br /><center>News Edited!";
						echo "<br /><a href=\"viewProject.php?id=".$_GET['id']."\">View Project</a></center>";
						unset($_SESSION['editprojectnewssuccess']);
					}
					else if($_SESSION['deletenewssuccess'])
					{
						echo "<br /><center>News Deleted!";
						echo "<br /><a href=\"viewProject.php?id=".$_GET['id']."\">View Project</a></center>";
						unset($_SESSION['deletenewssuccess']);
					}
					else if(isset($_GET['edit']))
					{
						$result = $database->query("SELECT * FROM ".TBL_PROJECT_NEWS." WHERE id='".$_GET['edit']."'");
						$news = mysql_fetch_array($result);
						$id = $news['id'];
						$projectID = $news['projectID'];
						$title = $news['title'];
						$content = $news['content'];
				?>
				<form action="includes/process.php" method="POST">
				<table cellspacing="0" cellpadding="3">
				<tr>
					<td align="left"><b>Title:</b> <? echo $form->error("title"); ?></td>
				</tr>
				<tr>
					<td><input type="text" name="title" maxlength="50" size="79" value="<? if($form->value("title")==""){ echo $title; }else{ echo $form->value("title"); } ?>" style="background-color: #bcc6e1;"></td>
				</tr>
				<tr>
					<td align="left"><b>Content:</b> <? echo $form->error("content"); ?></td>
				</tr>
				<tr>
					<td><textarea name="content" style="background-color: #bcc6e1;" cols="60" rows="10"><? if($form->value("content")==""){ echo $content; }else{ echo $form->value("content"); } ?></textarea></td>
				</tr>
				<tr>
					<td align="right">
						<input type="hidden" name="projectID" value="<?php echo $projectID; ?>">
						<input type="hidden" name="subEditProjectNews" value="<?php echo $id; ?>">
						<input type="submit" value="Save Project News">
					</td>
				</tr>
				</table>
				</form>
				<?php
					}
					else
					{
				?>
				<form action="includes/process.php" method="POST">
				<table cellspacing="0" cellpadding="3">
				<tr>
					<td align="left"><b><?php echo $lang['EDIT_PROJECT_NEWS_TILE']; ?></b> <? echo $form->error("title"); ?></td>
				</tr>
				<tr>
					<td><input type="text" name="title" maxlength="50" size="79" value="<? echo $form->value("title"); ?>" style="background-color: #bcc6e1;"></td>
				</tr>
				<tr>
					<td align="left"><b><?php echo $lang['EDIT_PROJECT_CONTENT']; ?></b> <? echo $form->error("content"); ?></td>
				</tr>
				<tr>
					<td><textarea name="content" style="background-color: #bcc6e1;" cols="60" rows="10"><? echo $form->value("content"); ?></textarea></td>
				</tr>
				<tr>
					<td align="right">
						<input type="hidden" name="subPostProjectNews" value="<?php echo $_GET['id']; ?>">
						<input type="submit" value="Post Project News">
					</td>
				</tr>
				</table>
				</form>
				<?php
					}
				?>
				</center>
				</td><td></td>
			</tr>
			<tr>
				<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
			</tr>
			</table>
			</center>
			<br /><br />
			<center>
			<table cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
			</tr>
			<tr bgcolor="#dadada">
				<td></td><td>
					<center><font size="+1"><b>Project News</b></font></center>
					<center><?php displayProjectNewsAdmin($_GET['id'],10); ?></center>
				</td><td></td>
			</tr>
			<tr>
				<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
			</tr>
			</table>
			</center>
			<?php
				}
			}
			?>
		</td>
		<td valign="top" width="14%">
	</tr>
	</table>
	</center>
<?php include("footer.php"); ?>